<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

require_once ADMIN.DS.HEAD;
?>

<div class='full'>
	<div class="submenu_container">
		<a class="submenu_button submenu_button_active" href='/admin/rumors/view'>Список</a>
		<a class="submenu_button" href='/admin/rumors/create'>Пустить слух</a>
	</div>
	<h3>Список слухов</h3>
	<?php
	$rumors = $db->getTable("select * from `rumors` order by `rumor_id` desc");
	$rumors_likes = $db->getTable("select * from `rumors_likes` order by `rumor_id` desc");
	
	$likes = array();
	
	foreach ($rumors as $rumor) {
		$likes[$rumor['rumor_id']] = array("like"=>0,"dislike"=>0);
	}
	
	foreach ($rumors_likes as $like) {
		$likes[$like['rumor_id']][$like['mean']]++;
	}
	
	if ($rumors){
		echo "<table class='message_list'>";
		echo "<tr class='messages_header'><td width='50'>Приоритет</td><td>Текст</td><td>Статистика</td><td class='actions'>Действия</td></tr>";
		foreach ($rumors as $rumor)
		{
			echo "<tr>";
				echo "<td>".$rumor['priority']."</td>";
				echo "<td>".$rumor['text']."</td>";
				echo "<td>";
					echo "<p>Верят: ".$likes[$rumor['rumor_id']]['like']."</p>";
					echo "<p>Не верят: ".$likes[$rumor['rumor_id']]['dislike']."</p>";
				echo "</td>";
				echo "<td class='actions'><a href='/admin/rumors/edit/".$rumor['rumor_id']."' class='send'>Редактировать</a><br /><a href='/admin/rumors/delete/".$rumor['rumor_id']."' class='delete'>Удалить</a></td>";
			echo "</tr>";
		}
		echo "</table>";
	}
	?>
</div>

<?php require_once ADMIN.DS.FOOTER; ?>